package com.sxu.greedy.day3;

/**
 * 增加字符串匹配
 */
public class Test13 {
    public int[] diStringMatch(String s) {
        int n = s.length();
        int left = 0, right = n;
        int[] ret = new int[n+1];
        for(int i = 0;i<n;i++){
            if(s.charAt(i)=='I'){
                ret[i] = left;
                left++;
            } else {
                ret[i] = right;
                right--;
            }
            // 使用三目运算符
            //ret[i] = s.charAt(i) == 'I'?left++:right--;
        }
        ret[n] = left;
        return ret;
    }
}
